package com.qf.controller;

import com.qf.pojo.Admin;
import com.qf.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("login")
    public String login(Admin admin, HttpSession session) {
        //登录方法
        boolean result = adminService.login(admin);

        //判断
        if (result) {
            System.out.println("ture");
            //登录成功以后把信息存储在session中用来验证拦截器
            session.setAttribute("admin", admin);
            //登陆成功，跳转到后台管理主页面
            return "redirect:http://localhost:8080/index.html";
        } else {
            System.out.println("false");
            //登录失败，跳转到登录页面
            return "redirect:http://localhost:8080/adminLogin.html";
        }

    }


}
